//
//  ViewController.m
//  完整的定制一个控件
//
//  Created by clz on 2019/10/5.
//  Copyright © 2019 clz. All rights reserved.
//

#import "ViewController.h"
#import <Masonry.h>
#import "MyCell.h"
#import "MyModel.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray <MyModel *>*dataArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.dataArray = [[NSMutableArray alloc]init];
    
    MyModel *model1 = [[MyModel alloc]init];
    model1.imageName = @"image01";
    model1.titleStr = @"我是title01";
    model1.subTitleStr = @"我是subtitle01";
    
    MyModel *model2 = [[MyModel alloc]init];
    model2.imageName = @"image02";
    model2.titleStr = @"我是title02";
    model2.subTitleStr = @"我是subtitle02";
    
    MyModel *model3 = [[MyModel alloc]init];
    model3.imageName = @"image03";
    model3.titleStr = @"我是title03";
    model3.subTitleStr = @"我是subtitle03";
    [self.dataArray addObject:model1];
    [self.dataArray addObject:model2];
    [self.dataArray addObject:model3];

    
    self.tableView = [[UITableView alloc]init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[MyCell class] forCellReuseIdentifier:@"MyCell"];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
}

#pragma mark-UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
    
    MyModel *model = self.dataArray[indexPath.row];
//    cell.itemImageView.image = [UIImage imageNamed:model.imageName];
//    cell.titleItemLabel.text = model.titleStr;
//    cell.subTitleItemLabel.text = model.subTitleStr;
    
//    __weak typeof(self) weakSelf = self;
//    cell.deleteBlock = ^{
//        [weakSelf.dataArray removeObject:model];
//        [weakSelf.tableView reloadData];
//    };
    
    [cell.myCellVM setModel:model];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}


/*MVC
 
 ）Model 和 View 永远不能相互通信，只能通过 Controller 传递。
 
 2）Controller 可以直接与 Model 对话。
 
 3）Controller 可以直接与 View 对话。
 
 */




@end
